// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.

#include "SmartMovieSceneBindingExtensions.h"
#include "SequencerScripting/Public/SequencerBindingProxy.h"
#include "MovieSceneSequence.h"
#include "MovieScene.h"

void USmartMovieSceneBindingExtensions::SmSetDisplayName(const FSequencerBindingProxy & InBinding, FString Name)
{
	UMovieScene* MovieScene = InBinding.Sequence ? InBinding.Sequence->GetMovieScene() : nullptr;
	if (MovieScene && InBinding.BindingID.IsValid()) {
		FMovieSceneSpawnable* MovieSceneSpawnable = MovieScene->FindSpawnable(InBinding.BindingID);
		FMovieScenePossessable* MovieScenePossessable = MovieScene->FindPossessable(InBinding.BindingID);
		if (MovieSceneSpawnable) {
			MovieSceneSpawnable->SetName(Name);
		}
		if (MovieScenePossessable) {
			MovieScenePossessable->SetName(Name);
		}
	}
}

UObject * USmartMovieSceneBindingExtensions::SmGetObject(const FSequencerBindingProxy & InBinding)
{
	UMovieScene* MovieScene = InBinding.Sequence ? InBinding.Sequence->GetMovieScene() : nullptr;
	if (MovieScene && InBinding.BindingID.IsValid()) {
		FMovieSceneSpawnable* MovieSceneSpawnable = MovieScene->FindSpawnable(InBinding.BindingID);
		if (MovieSceneSpawnable) {
			return MovieSceneSpawnable->GetObjectTemplate();
		}
	}
	return nullptr;
}
